#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <sys/types.h>

int main()    
{    
    pid_t id = fork();    
    if(id<0)    
    {    
        perror("fork");    
        exit(1);    
    }    
    if(id==0)//子进程代码    
    {    
        int count = 20;    
        while(count)    
        {    
            printf("[%d]我是子进程,我的pid是: %d\n",count,getpid());    
            sleep(1);    
            count--;    
        }    
        exit(11);//子进程执行完代码后退出                                                                                                                                
    }                                                                                                    
    //父进程代码    
    int status = 0;                                                                                     
    waitpid(id,&status,0);                                                                                  
    printf("等待子进程成功!\n");                                                                         
    printf("退出码:%d\n", (status >> 8) & 0xff);                                                                         
    printf("终止信号:%d\n", (status) & 0x7f);                                                                         
    return 0;     
}
